package com.yiqi.liebang.feature.setting.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.suozhang.framework.component.http.RxDataProcessFactory;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.framework.BaseActivity;
import com.suozhang.framework.utils.T;
import com.yiqi.liebang.R;
import com.yiqi.liebang.entity.bo.PublicBo;
import com.yiqi.liebang.entity.bo.RechargeBo;
import com.yiqi.liebang.framework.api.HomeApi;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class AlibbActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.alibb_money)
    TextView alibbMoney;
    @BindView(R.id.alibb_number_text)
    TextView alibbNumberText;
    @BindView(R.id.alibb_number)
    EditText alibbNumber;
    @BindView(R.id.alibb_name_text)
    TextView alibbNameText;
    @BindView(R.id.alibb_name)
    EditText alibbName;
    @BindView(R.id.alibb_remarks_text)
    TextView alibbRemarksText;
    @BindView(R.id.alibb_remarks)
    EditText alibbRemarks;
    @BindView(R.id.btn_alibb)
    TextView btnAlibb;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_alibb;
    }

    @Override
    protected void initInjector() {

    }

    double money;
    @Override
    protected void initData() {
        initToolBar(toolbar, "支付宝提现", true, true);
        money=getIntent().getDoubleExtra("money",0);
        alibbMoney.setText(money+"");
        btnAlibb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AM.api().createApiService(HomeApi.class).userWithdraw(new RechargeBo(0,money,alibbNumber.getText().toString(),"",alibbName.getText().toString()))
                        .compose(RxDataProcessFactory.dataPrepAndIoToMainTransformer())
                        .subscribe(new Observer<PublicBo>() {
                            @Override
                            public void onSubscribe(Disposable d) {
                                showLoading(d);
                            }

                            @Override
                            public void onNext(PublicBo friendBeans) {
                                dismissLoading();
                                Intent intent=new Intent();
                                intent.putExtra("alibb","1");
                                setResult(60001,intent);
                                finish();
                            }

                            @Override
                            public void onError(Throwable e) {
                                dismissLoading();
                                T.showShort(e.getMessage());
                            }

                            @Override
                            public void onComplete() {

                            }
                        });
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
